var btn = document.querySelector("button");
var inps = document.querySelectorAll("input")
// 获取地址栏的参数
var search = location.search


btn.onclick=function(){
    var n1= inps[0].value
    var p1 = inps[1].value;
    (async function(){
        var txt = await PromiseAjax({
            url:"./php/login.php",
            data :`username=${n1}&password=${p1}`
            
        })
        if(txt==1){
            // 设置cookie保存账号
            //输入框的name值
            setCookie("num",n1)
            // 判断search是否有值
            if(search){
                // 获取url中的地址
                var url2 = search.split("?url2=")[1]
                // console.log(url2)
                location= url2
            }else{
                location="./index.html"
            }
        }else{
            alert("账号或密码错误")
            location.reload()
        }
        // console.log(txt)
        
    })()
}
